namespace CinemaMaestro.DataLayer.Entity.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Actors",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FirstName = c.String(maxLength: 65536),
                        LastName = c.String(maxLength: 65536),
                        BirthDay = c.DateTime(nullable: false),
                        Image = c.Binary(maxLength: 65536),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Movies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(maxLength: 65536),
                        Duration = c.Int(nullable: false),
                        Description = c.String(maxLength: 65536),
                        ReleaseDate = c.DateTime(nullable: false),
                        Image = c.Binary(maxLength: 65536),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 65536),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Directors",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FirstName = c.String(maxLength: 65536),
                        LastName = c.String(maxLength: 65536),
                        BirthDay = c.DateTime(nullable: false),
                        Image = c.Binary(maxLength: 65536),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Screenings",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(nullable: false),
                        Price = c.Double(nullable: false),
                        DiscountedPrice = c.Double(nullable: false),
                        Language_Id = c.Int(),
                        Movie_Id = c.Int(),
                        Room_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Languages", t => t.Language_Id)
                .ForeignKey("dbo.Movies", t => t.Movie_Id)
                .ForeignKey("dbo.Rooms", t => t.Room_Id)
                .Index(t => t.Language_Id)
                .Index(t => t.Movie_Id)
                .Index(t => t.Room_Id);
            
            CreateTable(
                "dbo.Languages",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 65536),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Reservations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TicketNr = c.Int(nullable: false),
                        DiscountTicketNr = c.Int(nullable: false),
                        Name = c.String(maxLength: 65536),
                        Email = c.String(maxLength: 65536),
                        TelephoneNr = c.String(maxLength: 65536),
                        Screening_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Screenings", t => t.Screening_Id)
                .Index(t => t.Screening_Id);
            
            CreateTable(
                "dbo.Rooms",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 65536),
                        Capacity = c.Int(nullable: false),
                        Cinema_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Cinemas", t => t.Cinema_Id)
                .Index(t => t.Cinema_Id);
            
            CreateTable(
                "dbo.Cinemas",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 65536),
                        Address = c.String(maxLength: 65536),
                        TelephoneNr = c.String(maxLength: 65536),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Sales",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TicketNr = c.Int(nullable: false),
                        DiscountTicketNr = c.Int(nullable: false),
                        Total = c.Double(nullable: false),
                        Screening_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Screenings", t => t.Screening_Id)
                .Index(t => t.Screening_Id);
            
            CreateTable(
                "dbo.MovieActors",
                c => new
                    {
                        Movie_Id = c.Int(nullable: false),
                        Actor_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Movie_Id, t.Actor_Id })
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .ForeignKey("dbo.Actors", t => t.Actor_Id, cascadeDelete: true)
                .Index(t => t.Movie_Id)
                .Index(t => t.Actor_Id);
            
            CreateTable(
                "dbo.CategoryMovies",
                c => new
                    {
                        Category_Id = c.Int(nullable: false),
                        Movie_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Category_Id, t.Movie_Id })
                .ForeignKey("dbo.Categories", t => t.Category_Id, cascadeDelete: true)
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .Index(t => t.Category_Id)
                .Index(t => t.Movie_Id);
            
            CreateTable(
                "dbo.DirectorMovies",
                c => new
                    {
                        Director_Id = c.Int(nullable: false),
                        Movie_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Director_Id, t.Movie_Id })
                .ForeignKey("dbo.Directors", t => t.Director_Id, cascadeDelete: true)
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .Index(t => t.Director_Id)
                .Index(t => t.Movie_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Sales", "Screening_Id", "dbo.Screenings");
            DropForeignKey("dbo.Screenings", "Room_Id", "dbo.Rooms");
            DropForeignKey("dbo.Rooms", "Cinema_Id", "dbo.Cinemas");
            DropForeignKey("dbo.Reservations", "Screening_Id", "dbo.Screenings");
            DropForeignKey("dbo.Screenings", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.Screenings", "Language_Id", "dbo.Languages");
            DropForeignKey("dbo.DirectorMovies", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.DirectorMovies", "Director_Id", "dbo.Directors");
            DropForeignKey("dbo.CategoryMovies", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.CategoryMovies", "Category_Id", "dbo.Categories");
            DropForeignKey("dbo.MovieActors", "Actor_Id", "dbo.Actors");
            DropForeignKey("dbo.MovieActors", "Movie_Id", "dbo.Movies");
            DropIndex("dbo.DirectorMovies", new[] { "Movie_Id" });
            DropIndex("dbo.DirectorMovies", new[] { "Director_Id" });
            DropIndex("dbo.CategoryMovies", new[] { "Movie_Id" });
            DropIndex("dbo.CategoryMovies", new[] { "Category_Id" });
            DropIndex("dbo.MovieActors", new[] { "Actor_Id" });
            DropIndex("dbo.MovieActors", new[] { "Movie_Id" });
            DropIndex("dbo.Sales", new[] { "Screening_Id" });
            DropIndex("dbo.Rooms", new[] { "Cinema_Id" });
            DropIndex("dbo.Reservations", new[] { "Screening_Id" });
            DropIndex("dbo.Screenings", new[] { "Room_Id" });
            DropIndex("dbo.Screenings", new[] { "Movie_Id" });
            DropIndex("dbo.Screenings", new[] { "Language_Id" });
            DropTable("dbo.DirectorMovies");
            DropTable("dbo.CategoryMovies");
            DropTable("dbo.MovieActors");
            DropTable("dbo.Sales");
            DropTable("dbo.Cinemas");
            DropTable("dbo.Rooms");
            DropTable("dbo.Reservations");
            DropTable("dbo.Languages");
            DropTable("dbo.Screenings");
            DropTable("dbo.Directors");
            DropTable("dbo.Categories");
            DropTable("dbo.Movies");
            DropTable("dbo.Actors");
        }
    }
}
